package com.pet.server.ext.action.mall.product;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import com.pet.server.ext.ActionBase;
import com.pet.server.ext.ApiError;
import com.pet.server.ext.Result;
import com.pet.server.ext.data.ProductInfo;
import com.pet.server.ext.service.TbkService;
import com.pet.server.ext.util.JsonUtil;
import com.pet.server.ext.util.Parameters;
import com.pet.server.ext.util.StringUtil;

/**
 * 商品换一批
 * 
 * */
public class Around extends ActionBase{

	private Integer product_id;
	public Around(){
		 needCheckAuth =false;
	}
	
	@Override
	public void initParameters(Parameters params) throws ApiError {	
		
	}
	
	@Override
	public Result invokeService() throws ApiError {
		TbkService tbkService = new TbkService();
		List<ProductInfo> list = tbkService.queryProductData(100);
		
		Integer size=list.size();
		Set<Integer> set = new HashSet<>();
		while(set.size()<8&&set.size()<size){
			set.add(StringUtil.random(size));
		}
		List<ProductInfo> around_list = new ArrayList<>();
		for(Integer index:set){
			around_list.add(list.get(index));
		}
		
		Result result = new Result();
		result.put("data",JsonUtil.parseBaseJsonArray(around_list));
		return result;
	}
}
